﻿#region

using System;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using MidnightPeach.Forms;
using System.Linq;
#endregion

namespace MidnightPeach
{
    internal static class Program
    {
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            Application.ThreadException += Application_ThreadException;
            Application.Run(new MainForm());
        }

        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            if (e.Exception is ReflectionTypeLoadException)
            {
//                var types = (e.Exception as ReflectionTypeLoadException).Types.Select(x => x.FullName);
                var types = (e.Exception as ReflectionTypeLoadException).LoaderExceptions.Select(x => x.Message);
                var joinedTypes = string.Join(Environment.NewLine, types);

                string message = string.Format("아래 타입(들)을 로드할 수 없습니다.{0}Tool -> Import External File 을 실행한 후 이 타입(들)을 포함하고 있는 DLL(들)을 추가하세요.{0}{0}[중요] 추가 후 MP를 재실행하여야 합니다.{0}{0}{1}.", Environment.NewLine, joinedTypes);
                MessageBox.Show(message);
            }
            else
            {
                MessageBox.Show(e.Exception.Message);
            }
        }
    }
}